import java.awt.Color;
import java.awt.Font;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Random;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.NewImage;
import ij.plugin.PlugIn;
import ij.process.ImageProcessor;

// tester nuimersiquement l exemple de Jean-Paul


public class SuperImposeMonaColor extends ImagePlus implements PlugIn{
	
	private ImageProcessor primeIP; 
	private int X=2800,Y=2100; // image size
	
	private ImagePlus inverted;  
	private ImageProcessor inv_ip;  

	
	private boolean[][] masks={{true,true,false,false},{false,false,true,true},{true,false,false,true},
			                   {false,true,true,false},{true,false,true,false},{false,true,false,true}};
	
	
	private Random generator=new Random(1214); 
	
	private int masque[]={0xFF0000,0x00FF00,0x0000FF}; 
	private int decal[]={16,8,0};
	private int col=0; 
	
	public void run(String arg) {
		System.out.println("go");
		
		ImagePlus imp,imp1,imp2; 


		imp=IJ.openImage("C:/Users/decomite/Pictures/povray/VCS/RGB/BlueShare2.png");
		imp.setTitle("Blue");
		
		imp1=IJ.openImage("C:/Users/decomite/Pictures/povray/VCS/RGB/RedShare2.png");
		imp1.setTitle("Red");
	
		imp2=IJ.openImage("C:/Users/decomite/Pictures/povray/VCS/RGB/GreenShare2.png");
		imp2.setTitle("Green");


		
	
		primeIP=imp.getProcessor();
		X=primeIP.getWidth(); 
		Y=primeIP.getHeight(); 
		
		ImageProcessor primeIP1=imp1.getProcessor(); 
		ImageProcessor primeIP2=imp2.getProcessor(); 
		
		
        setStack(null, imp.getStack());
        setCalibration(imp.getCalibration()); 
		
        	show();
		
		
		for(int i=0;i<X;i++)
			for(int j=0;j<Y;j++){
				int val0=primeIP.get(i, j); 
				int val0R=(val0 &0xFF0000)>>16; 
			     int val0G=(val0 &0x00FF00)>>8;
			     int val0B=(val0 &0x0000FF); 
			     //System.out.println("1 "+val0R+" "+val0G+" "+val0B); 
				int val1=primeIP1.get(i,j);
				int val1R=(val1 &0xFF0000)>>16; 
			     int val1G=(val1 &0x00FF00)>>8;
			     int val1B=(val1 &0x0000FF);
			     //System.out.println("2 "+val1R+" "+val1G+" "+val1B); 
				int val2=primeIP2.get(i,j);
				int val2R=(val2 &0xFF0000)>>16; 
			     int val2G=(val2 &0x00FF00)>>8;
			     int val2B=(val2 &0x0000FF);
			     //System.out.println("3 "+val2R+" "+val2G+" "+val2B); 
			     int valResuR=(val0R | val1R | val2R)<<16; 
			     int valResuG=(val0G | val1G | val2G)<<8;
			     int valResuB=(val0B | val1B | val2B); 
			     //System.out.println("total "+(valResuR>>16)+" "+(valResuG>>8)+" "+valResuB); 
				primeIP.set(i, j, valResuR|valResuG|valResuB); 
			}

		

		
		primeIP.setFont(new Font(null,Font.ITALIC,60));
		primeIP.setColor(Color.RED);
		primeIP.setLineWidth(10); 
		
	
		setProcessor("Verifying", primeIP);
		
	
	
 		show(); 
 		System.out.println("fini"); 
	}
	
	
	

}
